//
//  TSZReprintCell.swift
//  微博天下
//
//  Created by Tsz on 15/10/14.
//  Copyright © 2015年 Tsz. All rights reserved.
//

import UIKit

let statusPictureMargin: CGFloat = 8.0


class TSZReprintCell: TSZStatusCell {
    //'重写 属性 didSet 不会覆盖父类的方法  ，子类只需要继续设置自己的内容即可
    //加载微博数据
    override var data: TSZHomeMircoblogModel?{
        didSet{
            //设置原创的出处
            let name = data?.retweeted_status?.user?.name ?? ""
             var text = data?.retweeted_status?.text ?? ""
            
            text = "@" + name + ":" + text
            reprintLabel.attributedText = TSZEmoticonsPackage.emoticonText(text, font: reprintLabel.font)
            
            
        }
    }
    
    //设置界面
    override func setupUI(){
        super.setupUI()
        
        //1、添加控件
        contentView.insertSubview(backButton, belowSubview:pictureView)
        
        contentView.insertSubview(reprintLabel, aboveSubview: backButton)
        
        //2、设置布局
        backButton.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: contentLabel, size: nil ,offset: CGPoint(x: -statusPictureMargin , y: statusPictureMargin) )
            
        backButton.ff_AlignVertical(type: ff_AlignType.TopRight, referView: buttomView, size: nil)
        //2、转发文本
        reprintLabel.ff_AlignInner(type: ff_AlignType.TopLeft, referView: backButton, size: nil ,offset: CGPoint(x: statusPictureMargin, y: statusPictureMargin))
        //3、配图试图
        let cons = pictureView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: reprintLabel, size: CGSize(width: 290 , height: 290), offset: CGPoint(x: 0, y: statusPictureMargin))
        
        pictureHightCons = pictureView.ff_Constraint(cons, attribute: NSLayoutAttribute.Height)
        pictureWigthCons = pictureView.ff_Constraint(cons, attribute: NSLayoutAttribute.Width)
        
        pictureTopCons = pictureView.ff_Constraint(cons, attribute: NSLayoutAttribute.Top)
    }
    
    
    //MARK - 懒加载文字
    private lazy var reprintLabel: FFLabel = {
        let label = FFLabel(color: UIColor.darkGrayColor(), fontSize: 14)
        
        label.labelDelegate = self
        label.numberOfLines = 0
//        label.preferredMaxLayoutWidth = UIScreen.mainScreen().bounds.size.width - 2 * 8.0
        
        label.preferredMaxLayoutWidth = UIScreen.mainScreen().bounds.size.width - 2 * statusPictureMargin
        return label
    }()
    

    //显示转发微博的内容的按钮 
    private lazy var backButton: UIButton = {
        let btn = UIButton()
        btn.backgroundColor = UIColor(white: 0.9, alpha: 1.0)
        return btn
    }()
}
